var express = require('express');
var router = express.Router();
var redis = require('redis');
var Member = require('../model/Member');
var Log = require('../model/Log');

router.post('/add', function(req, res) {
    var log = new Log();
    log.title = req.body.title;
    // 通过thirdSession查到目标Member
    // 读取redis
    var client = redis.createClient('6379', 'localhost');
    client.get(req.body.thirdSession, function(err, value) {
        console.log(value);
        var data = JSON.parse(value);
        var openid = data.openid;
        // 通过openid找到Member对象
        Member.findOne({
            openid: openid
        }).then(member => {
            console.log(member);
            log.member = member;
            log.save().then(data => {
                res.json(data);
            });
        });
    });

});

module.exports = router;